# Contributor: Carbon Jiao <http://archlive-pkg.googlecode.com>
pkgname=firefox-archlive-addons
pkgver=3.5
pkgrel=1
_ff_identifier={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
pkgdesc="Mozilla Firefox常用插件"
arch=('i686' 'x86_64')
license=('MPL' 'GPL' 'LGPL')
makedepends=()
depends=()
provides=()
conflicts=()
options=()
install=()
url="http://www.mozilla.org/projects/firefox"
source=(
  gladder.xpi #https://groups.google.com/group/gladder
  specilink_1.1.xpi #http://blogimg.chinaunix.net/blog/upfile2/090629162709.tar
  #http://g-fox.cn/chinaedition/addons/cpmanager/cpmanager-0.2.4.xpi  #中国版插件管理器，总是自己装新插件！
  http://g-fox.cn/chinaedition/addons/zoompanel/zoompanel-0.2.2.xpi
  http://g-fox.cn/chinaedition/addons/fontsetter/fontsetter-0.3.xpi	   #设置字体的插件
  http://g-fox.cn/chinaedition/addons/livemargins/livemargins-0.1.17.xpi
  http://g-fox.cn/chinaedition/addons/quicklaunch/quicklaunch-0.3.2.xpi
  http://g-fox.cn/chinaedition/addons/tabimprovelite/tabimprovelite-0.2.7.xpi
  #http://g-fox.cn/chinaedition/addons/personas/personas-1.2.xpi 
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/3755/addon-3755-latest.xpi #GUtil
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/10636/addon-10636-latest.xpi #Mason
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/2275/addon-2275-latest.xpi #Torbutton
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/398/addon-398-latest.xpi #Forecastfox
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/4891/addon-4891-latest.xpi #Vimperator
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/2987/addon-2987-latest.xpi #TabRenamizer 
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/3006/addon-3006-latest.xpi #Video DownloadHelper
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/5791/addon-5791-latest.xpi #Flagfox显示描述当前服务器位置的国旗
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/9591/addon-9591-latest.xpi #Power Twitter
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/7172/addon-7172-latest.jar #macosx_theme
  rssticker.xpi::"https://addons.mozilla.org/zh-CN/firefox/downloads/latest/2325/addon-2325-latest.xpi" #RSS Ticker
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/201/addon-201-latest.xpi #DownThemAll!
  autopager.xpi::"https://addons.mozilla.org/zh-CN/firefox/downloads/latest/4925/addon-4925-latest.xpi" #AutoPager
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/6076/addon-6076-latest.xpi #Better Gmail 2
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/9457/addon-9457-latest.xpi #Integrated GMail
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/433/addon-433-latest.xpi #Flashblock
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/1879/addon-1879-latest.xpi #MediaWrap
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/673/addon-673-latest.xpi #InFormEnter
  #https://addons.mozilla.org/zh-CN/firefox/downloads/latest/220/addon-220-latest.xpi #FlashGot
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/748/addon-748-latest.xpi #Greasemonkey
  http://dl.google.com/gears/current/gears-linux-opt.xpi
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/4808/addon-4808-latest.xpi #Google Reader Watcher
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/1865/addon-1865-latest.xpi #Adblock Plus
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/6623/addon-6623-latest.xpi #BetterPrivacy
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/4810/addon-4810-latest.xpi #Speed Dial 
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/6777/addon-6777-latest.xpi #IE8 Activities (Accelerators) 
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/1320/addon-1320-latest.xpi #Gmail manager
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/6113/addon-6113-latest.xpi  #新同文堂
  autoproxy.xpi::"https://addons.mozilla.org/zh-CN/firefox/downloads/file/49794/autoproxy-0.2.1+.2009032706-fx+tb+sm.xpi?confirmed"
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/2464/addon-2464-latest.xpi #FoxyProxy
  https://addons.mozilla.org/en-US/firefox/downloads/latest/2448/addon-2448-latest.xpi #gbookmarks
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/2410/addon-2410-latest.xpi #Xmarks (formerly Foxmarks) 
  FireFTP-1.0.5-CN.xpi #https://addons.mozilla.org/zh-CN/firefox/downloads/latest/684/addon-684-latest.xpi #FireFTP英文版
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/1237/addon-1237-latest.xpi #QuickJava
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/5258/addon-5258-latest.xpi # EmbeddedObjects 
  https://addons.mozilla.org/zh-CN/firefox/downloads/latest/7684/addon-7684-latest.xpi # Fire.FM
)
md5sums=()

_firefox-xpi-installer() {

  local _dir=${pkgdir}/usr/lib/firefox-${pkgver}/extensions
  mkdir -p "${_dir}/${_xpifile}"
  bsdtar -x -f $srcdir/${_xpifile} -C "${_dir}/${_xpifile}"
  find "${_dir}/${_xpifile}" -type f -exec chmod 0644 {} \;
  _identifier=`grep "em:id" "${_dir}/${_xpifile}"/install.rdf | awk 'BEGIN{FS="\""; RS="\""}$NF&&$NF!~/.*=.*/{print $1}' | head -1`
  if [ "${_identifier}" = "${_ff_identifier}" ]; then
     _identifier=`grep "em:id" "${_dir}/${_xpifile}"/install.rdf | awk 'BEGIN{FS="\""; RS="\""}$NF&&$NF!~/.*=.*/{print $1}' | sed -n '2p'`
  fi
  if [ "${_identifier}${_xpifile}" = "${_xpifile}" -o "x$(echo ${_identifier} | grep "em:id")" != "x" ]; then
         _identifier=`awk 'BEGIN{FS="<em:id>"; RS="</"}$NF&&$NF!~/.*>.*/{print $NF}' "${_dir}/${_xpifile}"/install.rdf | head -1`
         if [ "${_identifier}" = "${_ff_identifier}" ]; then
  	      _identifier=`awk 'BEGIN{FS="<em:id>"; RS="</"}$NF&&$NF!~/.*>.*/{print $NF}' "${_dir}/${_xpifile}"/install.rdf | sed -n '2p'`
         fi
  fi

  if [ "${_identifier}${_xpifile}" = "${_xpifile}" ]; then
        echo "插件${_xpifile}不支持目前的Firefox版本,请检查其install.rdf文件"
        rm -rf "${_dir}/${_xpifile}"
	  return 0
  else 
     mv "${_dir}/${_xpifile}" "${_dir}/${_identifier}"
     touch "${_dir}/${_identifier}/chrome.manifest"
     return 0
     chmod 777 "${_dir}/${_xpifile}"
  fi
}

build() {
  cd $startdir
  ls *.xpi *.jar > "${srcdir}/xpi"
  cd ${srcdir}
  cat "${srcdir}/xpi" | while read xpifile; do
    _xpifile=${xpifile}
    _firefox-xpi-installer || return 1
  done   
  chmod 777 ${pkgdir}/usr/lib/firefox-${pkgver}/extensions
}
